package com.twq.patternmatch.pattern.kinds

import com.twq.patternmatch.basic._

/**
 * Created by tangweiqun on 2017/12/8.
 * 模式的种类-构造器模式
 */
object Constructor {
  def main(args: Array[String]): Unit = {
    val expr: Expr = BinOp("-", UnOp("-", Var("x")), Var("y"))
    //4、构造器模式：Constructor patterns
    //4.1：支持深度匹配，比如下面的例子不仅匹配top-level的对象BinOp，还能匹配的到深一层次的对象Number
    expr match {
      case BinOp("+", e, Number(0)) => println("a deep match")
      case e: UnCaseClassExpr =>
      case _ =>
    }
  }
}

class UnCaseClassExpr(name: String) extends Expr
